package main

import (
	"flag"
	"fmt"
	"time"
)

const layout = "2006-01-02 15:04:05"

func main() {
	timestamp := flag.Int("stamp", 0, "time stamp")
	timestr := flag.String("str", "", "time string")
	now := flag.Bool("now", false, "get now stamp and string")
	flag.Parse()
	if *now {
		n := time.Now()
		fmt.Println("now string:", n.Format(layout))
		fmt.Println("now stamp:", n.Unix())
		return
	}
	if *timestamp != 0 {
		fmt.Println("time string:", time.Unix(int64(*timestamp), 0).Format(layout))
		return
	}
	if *timestr != "" {
		time, err := time.ParseInLocation(layout, *timestr, time.Local)
		if err != nil {
			fmt.Println(err)
			return
		}
		fmt.Println("time stamp:", time.Unix())
		return
	}
	fmt.Println("use flag now, stamp or str")
}
